package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺相关接口")
@RequestMapping("/admin/shop")
@RestController("adminShopController")
public class ShopController {
    @Autowired
    RedisTemplate redisTemplate;
    private final static String SHOP_STATUS = "SHOP_STATUS";

    /**
     * 设置店铺营业状态  --0 打样  1 营业
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺营业状态:{}",status);
        // 1.获取valueOperations对象
        ValueOperations valueOperations = redisTemplate.opsForValue();
        // 2.将店铺状态存入redis
        valueOperations.set(SHOP_STATUS,status);
        return Result.success();
    }
    @ApiOperation("获取店铺营业状态")
    @GetMapping("/status")
    public Result getStatus(){
        // 1.获取valueOperations对象
        ValueOperations valueOperations = redisTemplate.opsForValue();
        // 2.从redis获取店铺状态
        Integer status = (Integer) valueOperations.get(SHOP_STATUS);
        return Result.success(status);
    }
}
